/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.services;

import org.testis.data.TestStepDataObject;
import org.testis.data.TestStepException;
import org.testis.data.TestStepResultType;


/**
 * A factory class to create a module task object dynamically 
 * according to module type
 * @author nurhat
 */
public class AtofModuleTaskFactory
{

    public AtofModuleTask getInstance(TestStepDataObject dataObj)
    {
        AtofModuleServiceFactory factory = new AtofModuleServiceFactory();

        AtofModuleService service = factory.getInstance(dataObj.getModuleType());
        try {
            Class<?> cls =
                Class.forName("org.testis." + dataObj.getModuleType().
                              toLowerCase() +
                              ".services." + dataObj.getModuleType() + "Task");

            AtofModuleTask task = (AtofModuleTask) cls.getConstructors()[0].
                newInstance(new Object[]{dataObj, service});
            return task;
        } catch (Exception ex) {
            throw new TestStepException(TestStepResultType.MISTAKE,
                                        "(" + ex.getClass().getSimpleName() +
                                        ")Given module type" + dataObj.
                                        getModuleType() +
                                        " is not supported righ now at AtofModuleTaskFactory");

        }
    }
}
